package com.we.connect.weconnect.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.we.connect.weconnect.mapper.admin.SendUserInfoMapper;
import com.we.connect.weconnect.model.system.SendUserInfo;
import com.we.connect.weconnect.model.system.SysUser;
import com.we.connect.weconnect.service.SendUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SendUserInfoServiceImpl implements SendUserInfoService {

    @Autowired
    private SendUserInfoMapper sendUserInfoMapper;

    @Override
    public Boolean addSendUserInfo(SendUserInfo sendUserInfo) {
        int insert = sendUserInfoMapper.insert(sendUserInfo);
        if(insert != 1){
            return false;
        }
        return true;
    }

    @Override
    public List<SendUserInfo> getSendUserInfoList(SysUser sysUser) {
        QueryWrapper<SendUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", sysUser.getUserId());
        return sendUserInfoMapper.selectList(wrapper);
    }

    @Override
    public Boolean deleteSendUserInfo(Long id) {
        QueryWrapper<SendUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("table_id", id);
        int delete = sendUserInfoMapper.delete(wrapper);
        if(delete != 1){
            return false;
        }
        return true;
    }

    @Override
    public SendUserInfo findSendUserInfo(Long id) {
        QueryWrapper<SendUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("table_id", id);
        return sendUserInfoMapper.selectOne(wrapper);
    }

    @Override
    public Boolean updateSendUserInfo(SendUserInfo sendUserInfo) {
        QueryWrapper<SendUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("table_id", sendUserInfo.getTableId());
        int update = sendUserInfoMapper.update(sendUserInfo, wrapper);
        if(update != 1){
            return false;
        }
        return true;
    }

    @Override
    public List<SendUserInfo> findSendUserInfoList(SysUser sysUser) {
        QueryWrapper<SendUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", sysUser.getUserId());
        return sendUserInfoMapper.selectList(wrapper);
    }
}
